cf <- readRDS("data/campfire-tweets-2020-04-17.Rds")
Sources <- cf %>%
filter(str_detect(screen_name, "CALFIRE_ButteCo|Cal_Fire|ButteSheriff|ChicoPolice|ChicoFD|CountyOfButte|Paradise_CA"))
no_outliers <- top_n(Sources, -29, created_at_pst)
no_outliers %>%
group_by(screen_name) %>%
summarize(min(created_at_pst))
## # A tibble: 3 x 2
## screen_name `min(created_at_pst)`
## <chr> <dttm>
## 1 ButteSheriff 2018-11-08 08:03:55
## 2 CALFIRE_ButteCo 2018-11-08 06:51:47
## 3 ChicoFD 2018-11-08 07:46:17
no_outliers$screen_name <- as.factor(no_outliers$screen_name)
no_outliers %>% group_by(tweet_hour, screen_name, tweet_min) %>%
summarize(tweet_count=n()) %>%
ggplot(aes(x=tweet_hour, y=tweet_count, fill=screen_name)) + geom_col()
range(Sources$created_at_pst)
## [1] "2018-11-08 06:51:47 PST" "2018-12-19 13:46:14 PST"
plot.fav <- no_outliers %>% filter(favorite_count>1) %>% ggplot(aes(x=favorite_count, fill=screen_name)) + geom_histogram()
plot.rt <- no_outliers %>% filter(retweet_count>1) %>% ggplot(aes(x=retweet_count, fill=screen_name)) + geom_histogram()
plot.quo <- no_outliers %>% filter(quote_count>1) %>% ggplot(aes(x=quote_count, fill=screen_name)) + geom_histogram()
plot.rply <- no_outliers %>% filter(reply_count>1) %>% ggplot(aes(x=reply_count, fill=screen_name)) + geom_histogram()
gridExtra::grid.arrange(plot.fav, plot.rt, plot.quo, plot.rply, nrow=2)
name_levels <- c("CALFIRE_ButteCo", "ButteSheriff", "ChicoFD")
status_colors <- c("#0070C0", "#00B050", "#FFC000")
no_outliers$screen_name <- factor(no_outliers$screen_name, levels=name_levels, ordered=TRUE)
positions <- c(-2, -0.5, -1.0, 2, -1.5, 1.5, 1, .5, 2.5, -2.5)
directions <- c(1, -1)
line_pos <- data.frame(
"created_at_pst"=unique(no_outliers$created_at_pst),
"position"=rep(positions, length.out=length(unique(no_outliers$created_at_pst))),
"direction"=rep(directions, length.out=length(unique(no_outliers$created_at_pst)))
)
no_outliers <- merge(x=no_outliers, y=line_pos, by="created_at_pst", all = TRUE)
no_outliers <- no_outliers[with(no_outliers, order(created_at_pst, screen_name)), ]
head(no_outliers)
## created_at_pst user_id status_id created_at
## 1 2018-11-08 06:51:47 1711024998 1060545422651883520 2018-11-08 14:51:47
## 2 2018-11-08 07:46:17 3314757086 1060559137384226817 2018-11-08 15:46:17
## 3 2018-11-08 08:02:15 1711024998 1060563157691727872 2018-11-08 16:02:15
## 4 2018-11-08 08:03:55 787864658 1060563576790732800 2018-11-08 16:03:55
## 5 2018-11-08 08:15:46 1711024998 1060566559704342528 2018-11-08 16:15:46
## 6 2018-11-08 08:53:56 1711024998 1060576162710089728 2018-11-08 16:53:56
## screen_name
## 1 CALFIRE_ButteCo
## 2 ChicoFD
## 3 CALFIRE_ButteCo
## 4 ButteSheriff
## 5 CALFIRE_ButteCo
## 6 CALFIRE_ButteCo
## text
## 1 Firefighters are working to access a fire in the Camp Creek Road area near Highway 70 in the Feather River canyon. Estimated 10 acres and spreading. #CampFire
## 2 #chico residents are waking up to a large column of smoke coming from the Pulga area. #calfirebutte working the fire. Please do not call @ChicoPolice dispatch asking about the smoke. Follow @CALFIRE_ButteCo for updates https://t.co/uXnF5SpVja
## 3 #Campfire [Update], Fire is at 1000 acres. Dozens of resources being called in from throughout the State. https://t.co/5VpYRQhLcX
## 4 EVACUATION ORDER: Due to a fire in the area, an evacuation order has been issued for all of Pentz road in Paradise East to Highway 70.\n#ButteSheriff #CampFire
## 5 EVACUATION ORDER: Due to a fire in the area, an evacuation order has been issued for all of Pentz road in Paradise East to Highway 70.\n#ButteSheriff #CampFire
## 6 EVACUATION ORDER: Due to the fire in the area, an evacuation order has been issued for zones 2, 6, 7 and 13.\nIf assistance is needed in evacuating, please call 9 1 1.\n#ButteSheriff #CampFire
## source display_text_width reply_to_status_id reply_to_user_id
## 1 Twitter for Android NA <NA> <NA>
## 2 Twitter for iPhone 140 <NA> <NA>
## 3 Twitter for iPad 105 <NA> <NA>
## 4 Twitter for iPhone NA <NA> <NA>
## 5 Twitter for iPad NA <NA> <NA>
## 6 Twitter for Android NA <NA> <NA>
## reply_to_screen_name is_quote is_retweet favorite_count retweet_count
## 1 <NA> FALSE FALSE 65 63
## 2 <NA> TRUE FALSE 20 17
## 3 <NA> FALSE FALSE 98 103
## 4 <NA> FALSE FALSE 47 79
## 5 <NA> FALSE TRUE 0 0
## 6 <NA> FALSE TRUE 0 0
## quote_count reply_count hashtags symbols
## 1 11 9 NA NA
## 2 3 1 chico, calfirebutte NA
## 3 17 8 Campfire NA
## 4 16 7 NA NA
## 5 0 0 NA NA
## 6 0 0 NA NA
## urls_url urls_t.co
## 1 twitter.com/i/web/status/1… https://t.co/vVofVKMq6v
## 2 twitter.com/i/web/status/1… https://t.co/xjFJ2xDMKd
## 3 NA NA
## 4 twitter.com/i/web/status/1… https://t.co/RoVvY6GhK8
## 5 NA NA
## 6 NA NA
## urls_expanded_url
## 1 https://twitter.com/i/web/status/1060545422651883520
## 2 https://twitter.com/i/web/status/1060559137384226817
## 3 NA
## 4 https://twitter.com/i/web/status/1060563576790732800
## 5 NA
## 6 NA
## media_url media_t.co
## 1 NA NA
## 2 NA NA
## 3 http://pbs.twimg.com/media/DrfgI11X0AAoPUD.jpg https://t.co/5VpYRQhLcX
## 4 NA NA
## 5 NA NA
## 6 NA NA
## media_expanded_url
## 1 NA
## 2 NA
## 3 https://twitter.com/CALFIRE_ButteCo/status/1060563157691727872/photo/1
## 4 NA
## 5 NA
## 6 NA
## media_type
## 1 NA
## 2 NA
## 3 photo
## 4 NA
## 5 NA
## 6 NA
## ext_media_url
## 1 NA
## 2 NA
## 3 http://pbs.twimg.com/media/DrfgI11X0AAoPUD.jpg, http://pbs.twimg.com/media/DrfgI1yXcAYWsAS.jpg
## 4 NA
## 5 NA
## 6 NA
## ext_media_t.co
## 1 NA
## 2 NA
## 3 https://t.co/5VpYRQhLcX, https://t.co/5VpYRQhLcX
## 4 NA
## 5 NA
## 6 NA
## ext_media_expanded_url
## 1 NA
## 2 NA
## 3 https://twitter.com/CALFIRE_ButteCo/status/1060563157691727872/photo/1, https://twitter.com/CALFIRE_ButteCo/status/1060563157691727872/photo/1
## 4 NA
## 5 NA
## 6 NA
## ext_media_type mentions_user_id mentions_screen_name quoted_status_id
## 1 <NA> NA NA <NA>
## 2 <NA> NA NA 1060558426730913798
## 3 <NA> NA NA <NA>
## 4 <NA> NA NA <NA>
## 5 <NA> 787864658 ButteSheriff <NA>
## 6 <NA> 787864658 ButteSheriff <NA>
## quoted_text
## 1 <NA>
## 2 BREAKING: Butte County Sheriff's Office evacuating town of Pulga due to vegetation fire in the Feather River Canyon area near Camp Creek Road and Hwy 70. We have a reporter on the way to learn more now. https://t.co/OsfGMS7bKq
## 3 <NA>
## 4 <NA>
## 5 <NA>
## 6 <NA>
## quoted_created_at quoted_source quoted_favorite_count quoted_retweet_count
## 1 <NA> <NA> NA NA
## 2 2018-11-08 15:43:27 SocialNewsDesk 7 8
## 3 <NA> <NA> NA NA
## 4 <NA> <NA> NA NA
## 5 <NA> <NA> NA NA
## 6 <NA> <NA> NA NA
## quoted_user_id quoted_screen_name quoted_name quoted_followers_count
## 1 <NA> <NA> <NA> NA
## 2 43942200 ActionNewsNow Action News Now 18090
## 3 <NA> <NA> <NA> NA
## 4 <NA> <NA> <NA> NA
## 5 <NA> <NA> <NA> NA
## 6 <NA> <NA> <NA> NA
## quoted_friends_count quoted_statuses_count quoted_location
## 1 NA NA <NA>
## 2 424 49932 Chico, CA
## 3 NA NA <NA>
## 4 NA NA <NA>
## 5 NA NA <NA>
## 6 NA NA <NA>
## quoted_description
## 1 <NA>
## 2 KHSL-TV & KNVN Action News Now CBS 12 & NBC 24 Chico/Redding, CA
## 3 <NA>
## 4 <NA>
## 5 <NA>
## 6 <NA>
## quoted_verified retweet_status_id
## 1 NA <NA>
## 2 TRUE <NA>
## 3 NA <NA>
## 4 NA <NA>
## 5 NA 1060563576790732800
## 6 NA 1060572998606811136
## retweet_text
## 1 <NA>
## 2 <NA>
## 3 <NA>
## 4 <NA>
## 5 EVACUATION ORDER: Due to a fire in the area, an evacuation order has been issued for all of Pentz road in Paradise East to Highway 70.\n#ButteSheriff #CampFire
## 6 EVACUATION ORDER: Due to the fire in the area, an evacuation order has been issued for zones 2, 6, 7 and 13.\nIf assistance is needed in evacuating, please call 9 1 1.\n#ButteSheriff #CampFire
## retweet_created_at retweet_source retweet_favorite_count
## 1 <NA> <NA> NA
## 2 <NA> <NA> NA
## 3 <NA> <NA> NA
## 4 <NA> <NA> NA
## 5 2018-11-08 16:03:55 Twitter for iPhone 47
## 6 2018-11-08 16:41:22 Twitter for iPhone 51
## retweet_retweet_count retweet_user_id retweet_screen_name
## 1 NA <NA> <NA>
## 2 NA <NA> <NA>
## 3 NA <NA> <NA>
## 4 NA <NA> <NA>
## 5 79 787864658 ButteSheriff
## 6 84 787864658 ButteSheriff
## retweet_name retweet_followers_count retweet_friends_count
## 1 <NA> NA NA
## 2 <NA> NA NA
## 3 <NA> NA NA
## 4 <NA> NA NA
## 5 Butte County Sheriff 23122 178
## 6 Butte County Sheriff 23123 178
## retweet_statuses_count retweet_location
## 1 NA <NA>
## 2 NA <NA>
## 3 NA <NA>
## 4 NA <NA>
## 5 3144 Oroville, Ca.
## 6 3144 Oroville, Ca.
## retweet_description
## 1 <NA>
## 2 <NA>
## 3 <NA>
## 4 <NA>
## 5 Official Butte County Sheriff's Office page. This is a non-emergency communications tool. If you have an emergency, please dial 9-1-1.
## 6 Official Butte County Sheriff's Office page. This is a non-emergency communications tool. If you have an emergency, please dial 9-1-1.
## retweet_verified place_url place_name place_full_name place_type country
## 1 NA <NA> <NA> <NA> <NA> <NA>
## 2 NA <NA> <NA> <NA> <NA> <NA>
## 3 NA <NA> <NA> <NA> <NA> <NA>
## 4 NA <NA> <NA> <NA> <NA> <NA>
## 5 TRUE <NA> <NA> <NA> <NA> <NA>
## 6 TRUE <NA> <NA> <NA> <NA> <NA>
## country_code coords_coords bbox_coords
## 1 <NA> NA, NA NA, NA, NA, NA, NA, NA, NA, NA
## 2 <NA> NA, NA NA, NA, NA, NA, NA, NA, NA, NA
## 3 <NA> NA, NA NA, NA, NA, NA, NA, NA, NA, NA
## 4 <NA> NA, NA NA, NA, NA, NA, NA, NA, NA, NA
## 5 <NA> NA, NA NA, NA, NA, NA, NA, NA, NA, NA
## 6 <NA> NA, NA NA, NA, NA, NA, NA, NA, NA, NA
## status_url
## 1 https://twitter.com/CALFIRE_ButteCo/status/1060545422651883520
## 2 https://twitter.com/ChicoFD/status/1060559137384226817
## 3 https://twitter.com/CALFIRE_ButteCo/status/1060563157691727872
## 4 https://twitter.com/ButteSheriff/status/1060563576790732800
## 5 https://twitter.com/CALFIRE_ButteCo/status/1060566559704342528
## 6 https://twitter.com/CALFIRE_ButteCo/status/1060576162710089728
## name location
## 1 CAL FIRE Butte Unit/Butte County Fire Department Butte County CA
## 2 Chico Fire Department Chico, CA
## 3 CAL FIRE Butte Unit/Butte County Fire Department Butte County CA
## 4 Butte County Sheriff Oroville, Ca.
## 5 CAL FIRE Butte Unit/Butte County Fire Department Butte County CA
## 6 CAL FIRE Butte Unit/Butte County Fire Department Butte County CA
## description
## 1 This is the official Twitter account for the CAL FIRE/Butte County Fire Department. To report an emergency call 911.
## 2 Official Twitter page of the Chico Fire Department. Call 911 in an emergency.
## 3 This is the official Twitter account for the CAL FIRE/Butte County Fire Department. To report an emergency call 911.
## 4 Official Butte County Sheriff's Office page. This is a non-emergency communications tool. If you have an emergency, please dial 9-1-1.
## 5 This is the official Twitter account for the CAL FIRE/Butte County Fire Department. To report an emergency call 911.
## 6 This is the official Twitter account for the CAL FIRE/Butte County Fire Department. To report an emergency call 911.
## url protected followers_count
## 1 <NA> FALSE 31348
## 2 http://www.chico.ca.us/fire/home_page.asp FALSE 9826
## 3 <NA> FALSE 31349
## 4 http://www.buttecounty.net/sheriffcoroner FALSE 23122
## 5 <NA> FALSE 31349
## 6 <NA> FALSE 31348
## friends_count listed_count statuses_count favourites_count
## 1 204 370 4127 144
## 2 111 122 1608 332
## 3 204 370 4127 144
## 4 178 302 3144 338
## 5 204 370 4127 144
## 6 204 370 4127 144
## account_created_at verified profile_url profile_expanded_url account_lang
## 1 2013-08-29 21:41:37 TRUE <NA> <NA> NA
## 2 2015-08-14 05:12:38 TRUE <NA> <NA> NA
## 3 2013-08-29 21:41:37 TRUE <NA> <NA> NA
## 4 2012-08-28 21:13:17 TRUE <NA> <NA> NA
## 5 2013-08-29 21:41:37 TRUE <NA> <NA> NA
## 6 2013-08-29 21:41:37 TRUE <NA> <NA> NA
## profile_banner_url
## 1 https://pbs.twimg.com/profile_banners/1711024998/1557953138
## 2 https://pbs.twimg.com/profile_banners/3314757086/1523856896
## 3 https://pbs.twimg.com/profile_banners/1711024998/1557953138
## 4 https://pbs.twimg.com/profile_banners/787864658/1515089026
## 5 https://pbs.twimg.com/profile_banners/1711024998/1557953138
## 6 https://pbs.twimg.com/profile_banners/1711024998/1557953138
## profile_background_url
## 1 http://abs.twimg.com/images/themes/theme15/bg.png
## 2 http://abs.twimg.com/images/themes/theme1/bg.png
## 3 http://abs.twimg.com/images/themes/theme15/bg.png
## 4 http://abs.twimg.com/images/themes/theme19/bg.gif
## 5 http://abs.twimg.com/images/themes/theme15/bg.png
## 6 http://abs.twimg.com/images/themes/theme15/bg.png
## profile_image_url
## 1 http://pbs.twimg.com/profile_images/1128765334842773504/CoWZqIs1_normal.jpg
## 2 http://pbs.twimg.com/profile_images/689132857298518016/Kw-Bvwdu_normal.jpg
## 3 http://pbs.twimg.com/profile_images/1128765334842773504/CoWZqIs1_normal.jpg
## 4 http://pbs.twimg.com/profile_images/1190297689457614848/JlPTO-1q_normal.jpg
## 5 http://pbs.twimg.com/profile_images/1128765334842773504/CoWZqIs1_normal.jpg
## 6 http://pbs.twimg.com/profile_images/1128765334842773504/CoWZqIs1_normal.jpg
## year month day hour minute tweet_min tweet_hour lat lng
## 1 2018 11 8 6 51 2018-11-08 06:52:00 2018-11-08 07:00:00 NA NA
## 2 2018 11 8 7 46 2018-11-08 07:46:00 2018-11-08 08:00:00 NA NA
## 3 2018 11 8 8 2 2018-11-08 08:02:00 2018-11-08 08:00:00 NA NA
## 4 2018 11 8 8 3 2018-11-08 08:04:00 2018-11-08 08:00:00 NA NA
## 5 2018 11 8 8 15 2018-11-08 08:16:00 2018-11-08 08:00:00 NA NA
## 6 2018 11 8 8 53 2018-11-08 08:54:00 2018-11-08 09:00:00 NA NA
## position direction
## 1 -2.0 1
## 2 -0.5 -1
## 3 -1.0 1
## 4 2.0 -1
## 5 -1.5 1
## 6 1.5 -1
hour_buffer <- 2
date_range <- seq(min(no_outliers$created_at_pst) - hours(hour_buffer),
max(no_outliers$created_at_pst) + hours(hour_buffer), by='hour')
date_format <- format(date_range, '%H:%M')
date_df <- data.frame(date_range, date_format)
text_offset <- 0.05
no_outliers$text_position <- (text_offset * no_outliers$direction) +
no_outliers$position
no_outliers$text_output <- substr(no_outliers$text, 1, 20)
timeline_plot<-ggplot(no_outliers,aes(x=created_at_pst,y=0, col=screen_name,
label=text_output)) + labs(col="Tweets")
#timeline_plot<-timeline_plot+labs(col="Tweets")
timeline_plot<-timeline_plot+scale_color_manual(values=status_colors,
labels=name_levels, drop = FALSE)
timeline_plot<-timeline_plot+theme_classic()
# Plot horizontal black line for timeline
timeline_plot<-timeline_plot+geom_hline(yintercept=0,
color = "black", size=0.3)
# Plot vertical segment lines for texts
timeline_plot<-timeline_plot+geom_segment(data=no_outliers,
aes(y=position,yend=0,xend=created_at_pst),
color='black', size=0.2)
# Plot scatter points at zero and date
timeline_plot<-timeline_plot+geom_point(aes(y=0), size=3)
# Don't show axes, appropriately position legend
timeline_plot<-timeline_plot+theme(axis.line.y=element_blank(),
axis.text.y=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank(),
axis.ticks.y=element_blank(),
axis.text.x =element_blank(),
axis.ticks.x =element_blank(),
axis.line.x =element_blank(),
legend.position = "bottom"
)
# Show text for each hour
timeline_plot<-timeline_plot+geom_text(data=date_df,
aes(x=date_range,y=-0.1, label=date_format),
size=2.5,vjust=0.5, color='black', angle=45)
# Show text for each text
timeline_plot<-timeline_plot+geom_text(aes(y=text_position,label=text_output),size=2.5)
print(timeline_plot)
Second Plot Type
library(vistime)
vistime(no_outliers, events = "text_output", groups = "screen_name",
start = "created_at_pst", end = "created_at_pst")
And another
library(timelineS)
#timelineS(no_outliers, main = "Life of Michael Jackson")
news <- cf %>%
filter(str_detect(screen_name,"news|News") | str_detect(description, "news|News")) %>%
filter(verified=="TRUE")
news_orgs <- cf %>%
users_data() %>%
distinct(screen_name, .keep_all = TRUE) %>%
filter(str_detect(screen_name, "news|News") | str_detect(description, "news|News")) %>%
filter(verified=="TRUE") %>%
arrange(desc(followers_count))
news$user_type <- "news"
public <- anti_join(x = cf, y = news_orgs, by = "screen_name")
public$user_type <- "public"
cf <- rbind(public, news)
top.20.users <- news %>%
group_by(screen_name) %>%
summarise(n=n()) %>%
arrange(desc(n)) %>%
slice(1:20)
ggplot(top.20.users, aes(x = reorder(screen_name, -n), y=n)) +
geom_bar(stat="identity", fill="darkslategray")+
theme_minimal() + coord_flip() +
xlab("Users") + ylab("Count")
I’m interested in the sentiment difference between users who are considered a news outlet vs the general public. We plan to look at more individual political people like the Sheriff when going through this more thoroughly in our project.
ts1 <- tweet_words_nostop %>%
inner_join(get_sentiments("afinn"))
ts2 <- ts1 %>% group_by(status_id) %>% summarize(sentiment=sum(value))
cf2 <- Sources %>% left_join(ts2, by='status_id')
ggplot(cf2, aes(x=sentiment, col=screen_name)) + geom_density(lwd=2) + theme_minimal()